IF OBJECT_ID('sp_GetContentNewsByWebsiteLinkID') IS NOT NULL
DROP PROC sp_GetContentNewsByWebsiteLinkID
GO
create proc sp_GetContentNewsByWebsiteLinkID
@WebsiteLinkID int
as
begin
begin tran
SELECT * FROM ContentNews WHERE WebsiteLinkID  = @WebsiteLinkID
commit tran
end
GO

------Website--------------------
IF OBJECT_ID('sp_Website_GetAll') IS NOT NULL
DROP PROC sp_Website_GetAll
GO
create proc sp_Website_GetAll
as
begin
begin tran
	SELECT * FROM Website
commit tran
end
GO

IF OBJECT_ID('sp_Website_SelectByID') IS NOT NULL
DROP PROC sp_Website_SelectByID
GO
create proc sp_Website_SelectByID
@WebsiteID int
as
begin
begin tran
	SELECT * FROM Website where WebsiteID=@WebsiteID
commit tran
end
GO

IF OBJECT_ID('sp_Website_Insert') IS NOT NULL
DROP PROC sp_Website_Insert
GO
create proc sp_Website_Insert
@TenWebsite	nvarchar(150),
@WebsiteLink	nvarchar(MAX)
as
begin
begin tran
	insert into Website(TenWebsite,WebsiteLink,Xoa) values (@TenWebsite,@WebsiteLink,0)
commit tran
end

GO
IF OBJECT_ID('sp_Website_Update') IS NOT NULL
DROP PROC sp_Website_Update
GO
create proc sp_Website_Update
@WebsiteID	int,
@TenWebsite	nvarchar(150),
@WebsiteLink	nvarchar(MAX),
@Xoa	bit
as
begin
begin tran
	Update Website
	set TenWebsite=@TenWebsite,
	WebsiteLink=@WebsiteLink,
	Xoa=@Xoa
	where WebsiteID=@WebsiteID
commit tran
end
GO

---WebsiteLink--------
IF OBJECT_ID('sp_WebsiteLink_SelectByWebsiteID') IS NOT NULL
DROP PROC sp_WebsiteLink_SelectByWebsiteID
GO
create proc sp_WebsiteLink_SelectByWebsiteID
@WebsiteID	int
as
begin
begin tran
select * from WebsiteLink where WebsiteID=@WebsiteID
commit tran
end
GO

IF OBJECT_ID('sp_WebsiteLink_Insert') IS NOT NULL
DROP PROC sp_WebsiteLink_Insert
GO
create proc sp_WebsiteLink_Insert
@WebsiteLinkID	int,
@WebsiteID	int,
@TenChuDe	nvarchar(150),
@WebsiteLinkXpath	nvarchar(500),
@DiaChiWebsiteLink	nvarchar(500)
as
begin
begin tran
insert into WebsiteLink(WebsiteID,TenChuDe,WebsiteLinkXpath,DiaChiWebsiteLink,Xoa) values
(@WebsiteID,@TenChuDe,@WebsiteLinkXpath,@DiaChiWebsiteLink,0)
commit tran
end
GO

IF OBJECT_ID('sp_WebsiteLink_Update') IS NOT NULL
DROP PROC sp_WebsiteLink_Update
GO
create proc sp_WebsiteLink_Update
@WebsiteLinkID	int,
@WebsiteID	int,
@TenChuDe	nvarchar(150),
@WebsiteLinkXpath	nvarchar(500),
@DiaChiWebsiteLink	nvarchar(500),
@Xoa	bit
as
begin
begin tran
	Update WebsiteLink
	set WebsiteID = @WebsiteID,
	TenChuDe=@TenChuDe,
	WebsiteLinkXpath=@WebsiteLinkXpath,
	Xoa=@Xoa
	where WebsiteLinkID=@WebsiteLinkID
commit tran
end
GO
--------PageNews-----------
IF OBJECT_ID('sp_PageNews_Insert') IS NOT NULL
DROP PROC sp_PageNews_Insert
GO
create proc sp_PageNews_Insert
@WebsiteLinkID	int,
@PageLink	nvarchar(500)
as
begin
begin tran
	insert into PageNews(WebsiteLinkID,PageLink,Xoa) values (@WebsiteLinkID,@PageLink,0)
	
commit tran
end
GO

IF OBJECT_ID('sp_PageNews_Update') IS NOT NULL
DROP PROC sp_PageNews_Update
GO
create proc sp_PageNews_Update
@PageID	int,
@WebsiteLinkID	int,
@PageLink	nvarchar(500),
@Xoa	bit
as
begin
begin tran
	Update PageNews
	set WebsiteLinkID  =@WebsiteLinkID,
	PageLink=@PageLink,
	Xoa=@Xoa
	where PageID = @PageID
commit tran
end
GO	

IF OBJECT_ID('sp_PageNews_SelectByWebLinkID') IS NOT NULL
DROP PROC sp_PageNews_SelectByWebLinkID
GO
create proc sp_PageNews_SelectByWebLinkID
@WebsiteLinkID	int
as
begin
begin tran
	select * from PageNews where WebsiteLinkID=@WebsiteLinkID
commit tran
end
GO	

------ContentNews-----------
IF OBJECT_ID('sp_ContentNews_Update') IS NOT NULL
DROP PROC sp_ContentNews_Update
GO
create proc sp_ContentNews_Update
@ContentNewsID	int,
@WebsiteLinkID	int,
@PageNewsID	int,
@NoiDungHtml	ntext,
@Xpath	nvarchar(500),
@Xoa	bit
as
begin
begin tran
	Update ContentNews
	set WebsiteLinkID  =@WebsiteLinkID,
	PageNewsID = @PageNewsID,
	NoiDungHtml = @NoiDungHtml,
	Xpath=@Xpath,
	Xoa=@Xoa
	where ContentNewsID = @ContentNewsID
commit tran
end
GO

IF OBJECT_ID('sp_ContentNews_SelectByWebsiteLinkID') IS NOT NULL
DROP PROC sp_ContentNews_SelectByWebsiteLinkID
GO
create proc sp_ContentNews_SelectByWebsiteLinkID
@WebsiteLinkID	int
as
begin
begin tran
	Select * from ContentNews where WebsiteLinkID  = @WebsiteLinkID
commit tran
end
GO

IF OBJECT_ID('sp_ContentNews_SelectByPageNewsID') IS NOT NULL
DROP PROC sp_ContentNews_SelectByPageNewsID
GO
create proc sp_ContentNews_SelectByPageNewsID
@PageNewsID	int
as
begin
begin tran
	select * from ContentNews where PageNewsID=@PageNewsID
commit tran
end
GO
IF OBJECT_ID('sp_ContentNews_Insert') IS NOT NULL
DROP PROC sp_ContentNews_Insert
GO
create proc sp_ContentNews_Insert
@WebsiteLinkID	int,
@PageNewsID	int,
@NoiDungHtml	ntext,
@Xpath	nvarchar(500)
as
begin
begin tran
	insert into ContentNews (WebsiteLinkID,PageNewsID,NoiDungHtml,Xpath,Xoa) 
	values (@WebsiteLinkID,@PageNewsID,@NoiDungHtml,@Xpath,0)
commit tran
end
GO

---NgayDangTin----
IF OBJECT_ID('sp_NgayDangTin_Insert') IS NOT NULL
DROP PROC sp_NgayDangTin_Insert
GO
create proc sp_NgayDangTin_Insert
@ContentNewsID	int,
@NgayDangTin	date,
@Html	nvarchar(500),
@Xpath	nvarchar(500),
@Xoa	bit
as
begin
begin tran
	insert into NgayDangTin (ContentNewsID,NgayDangTin,Html,Xpath,Xoa) 
	values (@ContentNewsID,@NgayDangTin,@Html,@Xpath,0)
commit tran
end
GO
IF OBJECT_ID('sp_NgayDangTin_Update') IS NOT NULL
DROP PROC sp_NgayDangTin_Update
GO
create proc sp_NgayDangTin_Update
@NgayDangTinID	int,
@ContentNewsID	int,
@NgayDangTin	date,
@Html	nvarchar(500),
@Xpath	nvarchar(500),
@Xoa	bit
as
begin
begin tran
	update NgayDangTin
	set ContentNewsID=@ContentNewsID,
	NgayDangTin=@NgayDangTin,
	Html=@Html,
	Xpath=@Xpath,
	Xoa=@Xoa
	where NgayDangTinID=@NgayDangTinID
commit tran
end
GO
IF OBJECT_ID('sp_NgayDangTin_SelectByContentNewsID') IS NOT NULL
DROP PROC sp_NgayDangTin_SelectByContentNewsID
GO
create proc sp_NgayDangTin_SelectByContentNewsID
@ContentNewsID	int
as
begin
begin tran
select * from NgayDangTin where ContentNewsID = @ContentNewsID
commit tran
end
GO
-----TieuDeNoiDung---
IF OBJECT_ID('sp_TieuDeNoiDung_Insert') IS NOT NULL
DROP PROC sp_TieuDeNoiDung_Insert
GO
create proc sp_TieuDeNoiDung_Insert
@ContentNewsID	int,
@NoiDung	ntext,
@Html	ntext,
@Xpath	nvarchar(500)
as
begin
begin tran
	insert into TieuDeNoiDung (ContentNewsID,NoiDung,Html,Xpath,Xoa) 
	values (@ContentNewsID,@NoiDung,@Html,@Xpath,0)
commit tran
end
GO
IF OBJECT_ID('sp_TieuDeNoiDung_Update') IS NOT NULL
DROP PROC sp_TieuDeNoiDung_Update
GO
create proc sp_TieuDeNoiDung_Update
@TieuDeNoiDungID	int,
@ContentNewsID	int,
@NoiDung	ntext,
@Html	ntext,
@Xpath	nvarchar(500),
@Xoa	bit
	
as
begin
begin tran
	update TieuDeNoiDung
	set ContentNewsID=@ContentNewsID,
	NoiDung = @NoiDung,
	Html=@Html,
	Xpath=@Xpath,
	Xoa=@Xoa
	where TieuDeNoiDungID=@TieuDeNoiDungID
commit tran
end
GO
IF OBJECT_ID('sp_TieuDeNoiDung_SelectByContentNewsID') IS NOT NULL
DROP PROC sp_TieuDeNoiDung_SelectByContentNewsID
GO
create proc sp_TieuDeNoiDung_SelectByContentNewsID
@ContentNewsID	int
as
begin
begin tran
select * from TieuDeNoiDung where ContentNewsID = @ContentNewsID
commit tran
end
GO
----TomTatNoiDung----
IF OBJECT_ID('sp_TomTatNoiDung_Insert') IS NOT NULL
DROP PROC sp_TomTatNoiDung_Insert
GO
create proc sp_TomTatNoiDung_Insert
@ContentNewsID	int,
@NoiDung	ntext,
@Html	ntext,
@Xpath	nvarchar(500)
as
begin
begin tran
	insert into TomTatNoiDung (ContentNewsID,NoiDung,Html,Xpath,Xoa) 
	values (@ContentNewsID,@NoiDung,@Html,@Xpath,0)
commit tran
end
GO
IF OBJECT_ID('sp_TomTatNoiDung_Update') IS NOT NULL
DROP PROC sp_TomTatNoiDung_Update
GO
create proc sp_TomTatNoiDung_Update
@TomTatNoiDungID	int,
@ContentNewsID	int,
@NoiDung	ntext,
@Html	ntext,
@Xpath	nvarchar(500),
@Xoa	bit
as
begin
begin tran
	update TomTatNoiDung
	set ContentNewsID=@ContentNewsID,
	NoiDung = @NoiDung,
	Html=@Html,
	Xpath=@Xpath,
	Xoa=@Xoa
	where TomTatNoiDungID=@TomTatNoiDungID
commit tran
end
GO
IF OBJECT_ID('sp_TomTatNoiDung_SelectByContentNewsID') IS NOT NULL
DROP PROC sp_TomTatNoiDung_SelectByContentNewsID
GO
create proc sp_TomTatNoiDung_SelectByContentNewsID
@ContentNewsID	int
as
begin
begin tran
select * from TomTatNoiDung where ContentNewsID = @ContentNewsID
commit tran
end
GO

-----------HinhDaiDien-----
IF OBJECT_ID('sp_HinhDaiDien_Insert') IS NOT NULL
DROP PROC sp_HinhDaiDien_Insert
GO
create proc sp_HinhDaiDien_Insert
@HinhID	int,
@ContentNewsID	int,
@NoiDung	image,
@LinkHinh	nvarchar(500),
@Html	nvarchar(500),
@Xpath	nvarchar(500),
@Xoa	bit
	
as
begin
begin tran
	insert into HinhDaiDien (ContentNewsID,NoiDung,LinkHinh,Html,Xpath,Xoa) 
	values (@ContentNewsID,@NoiDung,@LinkHinh,@Html,@Xpath,0)
commit tran
end
GO
IF OBJECT_ID('sp_HinhDaiDien_Update') IS NOT NULL
DROP PROC sp_HinhDaiDien_Update
GO
create proc sp_HinhDaiDien_Update
@HinhID	int,
@ContentNewsID	int,
@NoiDung	image,
@LinkHinh	nvarchar(500),
@Html	nvarchar(500),
@Xpath	nvarchar(500),
@Xoa	bit
as
begin
begin tran
	update HinhDaiDien
	set ContentNewsID=@ContentNewsID,
	NoiDung = @NoiDung,
	LinkHinh=@LinkHinh,
	Html=@Html,
	Xpath=@Xpath,
	Xoa=@Xoa
	where HinhID = @HinhID
commit tran
end
GO
IF OBJECT_ID('sp_HinhDaiDien_SelectByContentNewsID') IS NOT NULL
DROP PROC sp_HinhDaiDien_SelectByContentNewsID
GO
create proc sp_HinhDaiDien_SelectByContentNewsID
@ContentNewsID	int
as
begin
begin tran
select * from HinhDaiDien where ContentNewsID = @ContentNewsID
commit tran
end
GO
-----GetMAX---
if OBJECT_ID('sp_ContentNews_MaxID') is not null
drop proc sp_ContentNews_MaxID
go
create proc sp_ContentNews_MaxID
as
begin
 select MAX(ContentNewsID)as ID from ContentNews
end
go
if OBJECT_ID('sp_HinhDaiDien_MaxID') is not null
drop proc sp_HinhDaiDien_MaxID
go
create proc sp_HinhDaiDien_MaxID
as
begin
select MAX(HinhID) as ID from HinhDaiDien
end
go
if OBJECT_ID('sp_NgayDangTin_MaxID') is not null
drop proc sp_NgayDangTin_MaxID
go
create proc sp_NgayDangTin_MaxID
as
begin
select MAX(NgayDangTinID) as ID from NgayDangTin
end
go
if OBJECT_ID('sp_PageNews_MaxID') is not null
drop proc sp_PageNews_MaxID
go
create proc sp_PageNews_MaxID
as
begin
select MAX(PageID) as ID from PageNews
end
go
if OBJECT_ID('sp_TieuDeNoiDung_MaxID') is not null
drop proc sp_TieuDeNoiDung_MaxID
go
create proc sp_TieuDeNoiDung_MaxID
as
begin
 select MAX(TieuDeNoiDungID) as ID from TieuDeNoiDung
end
go
if OBJECT_ID('sp_TomTatNoiDung_MaxID') is not null
drop proc sp_TomTatNoiDung_MaxID
go
create proc sp_TomTatNoiDung_MaxID
as
begin
select MAX(TomTatNoiDungID) as ID from TomTatNoiDung
end
go
if OBJECT_ID('sp_Website_MaxID') is not null
drop proc sp_Website_MaxID
go
create proc sp_Website_MaxID
as
begin
select MAX(WebsiteID) as ID from Website
end
go
if OBJECT_ID('sp_WebsiteLink_MaxID') is not null
drop proc sp_WebsiteLink_MaxID
go
create proc sp_WebsiteLink_MaxID
as
begin
select MAX(WebsiteLinkID) as ID from WebsiteLink
end
go
